package day1027.CarRentalCompany;

import java.util.Scanner;

//汽车业务类
public class AutomobileBusiness {
    Scanner input = new Scanner(System.in);
    int pos = 2;
    Car c[] = new Car[20];
    LeaseInformation p[] = new LeaseInformation[100];
    int pos2 = 0;
    public void chushihua(){
        c[0]= new Carriage("轿车","路虎","皖N12345",5,1000.00,true);
        c[1]= new PassengerCar("客车","大金杯","京A88888",20,1800.00,true);

    }
    //查看车辆情况
    public void check(){
        for (int i = 0;i<pos;i++){
            if(!c[i].isState()){
                continue;
            }
            System.out.print(c[i].getType()+"   "+c[i].getBrand()+"   "+c[i].getCarnumber()+"   "+c[i].getSeatnum()+"   "+c[i].getRent());
            if (c[i].isState()){
                System.out.println("当前可租");
            }
        }
    }
    //租赁
    public void lease( ){
        System.out.println("请输入姓名：");
        String name = input.next();
        System.out.println("请选择要租赁的类型：（1. 轿车 2. 客车）");
        int choice = input.nextInt();
        for (int j = 0;j<pos;j++){
            if(!c[j].isState()){
                continue;
            }
            if (choice==1){
                if (c[j].getType().equals("轿车")){
                    System.out.print(c[j].getType()+"   "+c[j].getBrand()+"   "+c[j].getCarnumber()+"   "+c[j].getSeatnum()+"   "+c[j].getRent());
                }
            }
            if (choice==2){
                if (c[j].getType().equals("客车")){
                    System.out.print(c[j].getType()+"   "+c[j].getBrand()+"   "+c[j].getCarnumber()+"   "+c[j].getSeatnum()+"   "+c[j].getRent());
                }
            }
        }
        System.out.println("请输入选择的车牌号");
        String carnumber = input.next();
        System.out.println("请输入租赁的天数");
        int day = input.nextInt();
        for (int i = 0;i<pos;i++){
                if(!c[i].isState()){
                    continue;
                }
            if (c[i].getCarnumber().equals(carnumber)){
                System.out.println("租赁成功");
                System.out.print(c[i].getType()+""+c[i].getBrand()+""+c[i].getCarnumber()+""+c[i].getSeatnum()+""+c[i].getRent());
                System.out.println("价格为："+c[i].calculate(day));
                c[i].setState(false);
                p[pos2]=new LeaseInformation(name,c[i].getBrand(),day,c[i].calculate(day));
                pos2++;
            }
        }
    }
    //还车
    public void returncar(String carnumber){
        for (int i = 0;i<pos;i++){
            if (c[i].getCarnumber().equals(carnumber)&&!c[i].isState()){
                c[i].setState(true);
                System.out.println("还车成功");
                return;
            }
        }
        System.out.println("还车失败");
        System.out.println("请确认车辆信息");

    }
    //报废
    public void scrap(String carnumber){
        for (int i = 0;i<pos;i++){
            if (c[i].getCarnumber().equals(carnumber)){
                c[i]=null;
                for (int j = i;j<pos;j++){
                    c[j]=c[j+1];
                    c[pos-1]=null;
                }
                System.out.println("报废成功");
                pos--;
                return;
            }
        }
        System.out.println("换车失败");
        System.out.println("请确认车辆信息");
    }
    //采购车辆
    public void add(){
        System.out.println("请输入要采购的汽车信息");
        System.out.println("--------------------");
        System.out.println("汽车品牌：");
        String brand = input.next();
        System.out.println("汽车车牌号：");
        String carnumber = input.next();
        System.out.println("汽车座位数：");
        int seatnum = input.nextInt();
        System.out.println("汽车价格");
        double rent = input.nextDouble();
        for (;;){
            System.out.println("请选择要采购车辆的信息(1.轿车  2.客车)：");
            System.out.println("请选择：");{
                int choice = input.nextInt();
                if (choice==1){
                    c[pos]= new Carriage("轿车",brand,carnumber,seatnum,rent,true);
                    pos++;
                    return;
                }
                if (choice==2){
                    c[pos]= new PassengerCar("客车",brand,carnumber,seatnum,rent,true);
                    pos++;
                    return;
                }
            }
        }
    }
    //车辆租赁记录
    public void carshow(){
        for (int i = 0;i<pos2;i++){
            p[i].show();
        }
    }
}
